using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Data.SqlClient;
using Entities;
/// <summary>
/// Summary description for BangGiaDAL
/// </summary>
namespace DataAccess
{

    public class BangGiaDAL : BaseDAL
    {
        #region Private Variables

        #endregion

        #region Public Constructors
        public BangGiaDAL()
        {
            //
            // TODO: Add constructor logic here
            //

        }
        #endregion



        #region Public Methods
        public int Insert(BangGia objBangGia)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_sp_sp_sp_BangGia_Insert";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@KhoaHoc", SqlDbType.BigInt);
            Sqlparam.Value = objBangGia.KhoaHoc;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@HangXe", SqlDbType.BigInt);
            Sqlparam.Value = objBangGia.HangXe;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LoaiGio", SqlDbType.Int);
            Sqlparam.Value = objBangGia.LoaiGio;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Gia", SqlDbType.Decimal);
            Sqlparam.Value = objBangGia.Gia;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@ID", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);


            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ID"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ID"].Value);

            return result;
        }

        public int Update(BangGia objBangGia)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_sp_sp_sp_BangGia_UpdateByPK";
            SqlParameter Sqlparam;

            Sqlparam = new SqlParameter("@Khoa", SqlDbType.BigInt);
            Sqlparam.Value = objBangGia.Khoa;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@KhoaHoc", SqlDbType.BigInt);
            Sqlparam.Value = objBangGia.KhoaHoc;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@HangXe", SqlDbType.BigInt);
            Sqlparam.Value = objBangGia.HangXe;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@LoaiGio", SqlDbType.Int);
            Sqlparam.Value = objBangGia.LoaiGio;
            Sqlcomm.Parameters.Add(Sqlparam);

            Sqlparam = new SqlParameter("@Gia", SqlDbType.Decimal);
            Sqlparam.Value = objBangGia.Gia;
            Sqlcomm.Parameters.Add(Sqlparam);



            Sqlparam = new SqlParameter("@ErrorCode", SqlDbType.Int);
            Sqlparam.Direction = ParameterDirection.ReturnValue;
            Sqlcomm.Parameters.Add(Sqlparam);

            int result = base.ExecuteNoneQuery(Sqlcomm);

            if (!Convert.IsDBNull(Sqlcomm.Parameters["@ErrorCode"]))
                result = Convert.ToInt32(Sqlcomm.Parameters["@ErrorCode"].Value);

            return result;


        }

        public int Delete(BangGia objBangGia)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_sp_sp_sp_BangGia_DeleteByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Khoa", SqlDbType.BigInt);
            Sqlparam.Value = objBangGia.Khoa;
            Sqlcomm.Parameters.Add(Sqlparam);



            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public int DeleteAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_sp_sp_sp_BangGia_DeleteAll";

            int result = base.ExecuteNoneQuery(Sqlcomm);
            return result;
        }

        public BangGia Select(BangGia objBangGia)
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_sp_sp_sp_BangGia_GetByPK";
            SqlParameter Sqlparam;


            Sqlparam = new SqlParameter("@Khoa", SqlDbType.BigInt);
            Sqlparam.Value = objBangGia.Khoa;
            Sqlcomm.Parameters.Add(Sqlparam);



            DataSet ds = base.GetDataSet(Sqlcomm);
            DataRow dr = null;
            if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
            {
                dr = ds.Tables[0].Rows[0];
                if (!Convert.IsDBNull(dr["Khoa"]))
                    objBangGia.Khoa = Convert.ToInt64(dr["Khoa"]);
                if (!Convert.IsDBNull(dr["KhoaHoc"]))
                    objBangGia.KhoaHoc = Convert.ToInt64(dr["KhoaHoc"]);
                if (!Convert.IsDBNull(dr["HangXe"]))
                    objBangGia.HangXe = Convert.ToInt64(dr["HangXe"]);
                if (!Convert.IsDBNull(dr["LoaiGio"]))
                    objBangGia.LoaiGio = Convert.ToInt32(dr["LoaiGio"]);
                if (!Convert.IsDBNull(dr["Gia"]))
                    objBangGia.Gia = Convert.ToDecimal(dr["Gia"]);

            }
            return objBangGia;
        }

        public ArrayList SelectAllToArray()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_sp_sp_sp_BangGia_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;
            ArrayList arrBangGia = new ArrayList();
            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];
                foreach (DataRow dr in dt.Rows)
                {
                    BangGia objBangGia = new BangGia();
                    if (!Convert.IsDBNull(dr["Khoa"]))
                        objBangGia.Khoa = Convert.ToInt64(dr["Khoa"]);
                    if (!Convert.IsDBNull(dr["KhoaHoc"]))
                        objBangGia.KhoaHoc = Convert.ToInt64(dr["KhoaHoc"]);
                    if (!Convert.IsDBNull(dr["HangXe"]))
                        objBangGia.HangXe = Convert.ToInt64(dr["HangXe"]);
                    if (!Convert.IsDBNull(dr["LoaiGio"]))
                        objBangGia.LoaiGio = Convert.ToInt32(dr["LoaiGio"]);
                    if (!Convert.IsDBNull(dr["Gia"]))
                        objBangGia.Gia = Convert.ToDecimal(dr["Gia"]);
                    arrBangGia.Add(objBangGia);
                }
            }
            return arrBangGia;
        }

        public DataTable SelectAll()
        {

            SqlCommand Sqlcomm = new SqlCommand();
            Sqlcomm.CommandType = CommandType.StoredProcedure;
            Sqlcomm.CommandText = "sp_sp_sp_sp_BangGia_GetAll";

            DataSet ds = base.GetDataSet(Sqlcomm);
            DataTable dt = null;

            if (ds != null && ds.Tables.Count > 0)
            {
                dt = ds.Tables[0];

            }
            return dt;
        }


        #endregion

    }

}
